package com.systop.score.controller;

import com.systop.common.pojo.Score;
import com.systop.common.util.CommonResult;
import com.systop.common.vo.ScoreVo;
import com.systop.score.feign.StudentFeign;
import com.systop.score.service.ScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/score")
@Api(tags = "Score",description = "成绩模块",hidden = false)
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @Autowired
    private StudentFeign studentFeign;


    @ApiOperation("根据学号、课程号查询成绩")
    @GetMapping("/findByscore/{c_id}/{s_no}")
    public CommonResult findByscore(@PathVariable("c_id") Integer c_id,@PathVariable("s_no") String s_no){
        CommonResult commonResult1 = scoreService.findScoreByscid(s_no, c_id);
        CommonResult commonResult2 = studentFeign.findbyname(s_no);

        Score score = (Score) commonResult1.getData();
        HashMap stu = (HashMap) commonResult2.getData();
        String s_name = (String) stu.get("s_name");

        ScoreVo scoreVo = new ScoreVo();
        scoreVo.setId(score.getId());
        scoreVo.setS_no(score.getS_no());
        scoreVo.setS_name(s_name);
        scoreVo.setC_id(score.getC_id());
        scoreVo.setScore(score.getScore());



        return new CommonResult(200,"ok",1,scoreVo);
    }
}
